package com.wrk._2_数组._02_习题;

import java.util.Arrays;
import java.lang.reflect.Array;

public class _007_求方差 {
    public static void main(String[] args) {
        //定义数组
        int [] array = {10,9,17,16};
        //求数组元素和
        int sum = Arrays.stream(array).sum();
        //求数组平均值
        int averageValue = sum / array.length ;
        //数组平方和
        double sumOfSquares = Arrays.stream(array).map(n -> (n - averageValue) * n).sum();
        //求标准方差
        double standardDeviation = sumOfSquares / (array.length - 1);
        //保留两位小数
        String formatted = String.format("%.2f", standardDeviation);
        System.out.println("标准方差为："+formatted);
    }
}
